<?php
error_reporting(7);

if (empty($_POST[action])) {
        $templatelist = "mail,navbar_sendemail,mail_recommendtofriend_content";
        require "global.php";

        if ($pauserinfo[userid] == 0) {
                show_nopermission();
        } 

        $articleid = intval($_GET[articleid]);

        if (empty($articleid)) {
                $nav = $_SERVER["REQUEST_URI"];
                $script = $_SERVER["SCRIPT_NAME"];
                $nav = ereg_replace("^$script", "", urldecode($nav));
                $vars = explode("/", $nav);
                $articleid = intval($vars[1]);
                if (!empty($vars[2])) {
                        $pagenum = intval($vars[2]);
                } 
        } 

        $article = validate_articleid($articleid);
        cachesorts();
        $article[tmp_title] = $article[title];

        eval("\$navbit = \"" . gettemplate('navbar_joiner') . "\";");
        eval("\$navbit .= \"" . gettemplate('navbar_sendemail') . "\";");

        $article[title] = "<a href=\"$phparticleurl/article.php/$articleid\">$article[title]</a>$navbit";
        $navbar = makearticlenavbar($article);
        $article[title] = $article[tmp_title]; 
        // eval("\$navbar = \"".gettemplate('navbar')."\";");
        eval("\$content = \"" . gettemplate('mail_recommendtofriend_content', 0) . "\";");
        eval("dooutput(\"" . gettemplate('recommendarticle') . "\");");
} 

if ($_POST[action] == "send") {
        $templatelist = "mail_recommendtofriend_subject,mail_recommendtofriend_mailcontent";
        require "global.php";

        if ($pauserinfo[userid] == 0) {
                show_nopermission();
        } 

        $articleid = intval($_POST[articleid]);
        $article = validate_articleid($articleid);

        $mailto = trim($_POST[mailto]);
        if (!pa_isset($_POST[recipients])) {
                show_errormessage("error_email_recipients_blank");
        } 
        if (!validate_email($mailto)) {
                show_errormessage("error_invalemail");
        } 
        eval("\$subject = \"" . gettemplate('mail_recommendtofriend_subject', 0) . "\";"); 
        // $subject = stripslashes($subject);
        eval("\$mailcontent = \"" . gettemplate('mail_recommendtofriend_mailcontent', 0) . "\";");
        $mailcontent = stripslashes($mailcontent);

        mail($mailto, $subject, $mailcontent, "From: $pauserinfo[email]\r\n");

        redirect("article.php?articleid=$articleid&pagenum=" . intval($_POST[pagenum]), "redirect_email_sended");
} 

?>